﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;

namespace Group16.Class_Library
{
    public class DataBaseInteraction
    {
        static public SqlConnection Connection;
        
        static public void OpenConnection()
        {
            string cntString = "Server = MALLA-PC\\SQLEXPRESS; uid=sa; pwd=123456;Database = ElectronicDevicesDatabase";
            Connection = new SqlConnection(cntString);
            Connection.Open();
        }
        static public object ExecuteCommand(string comText, int type)
        {
            
            using (SqlCommand command = new SqlCommand())
            {
                OpenConnection();
                command.CommandText = comText;
                command.Connection = Connection;
                
                if (type == 1)
                {
                    command.ExecuteNonQuery();
                    return null;
                }
                else if (type == 2)
                    return command.ExecuteReader();
                else
                    return command.ExecuteScalar();
            }
        }
        static public object ExecuteAdapter(string command)
        {
            OpenConnection();
            return new SqlDataAdapter(command, Connection);
        }
    }
}
